define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_agent_credit(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"store_id":"001","store_name":"世达","credit_line":10000,"credit":[{"info_id":"123456789","credit_line":1000,"new_debt":100,"repayment":900,"now_debt":200,"time":"2017/02/28","voucher":[{"id":"001","image":"img/bg-kef-img.png"},{"id":"002","image":"img/bg-kef-img.png"}]},{"info_id":"223456789","credit_line":1000,"new_debt":100,"repayment":900,"now_debt":200,"time":"2017/02/28","voucher":[{"id":"001","image":"img/bg-kef-img.png"},{"id":"002","image":"img/bg-kef-img.png"}]}],"now_debt":9999},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		};

		//返回信息
		return {
			//还款一览。参数：type repay：收款，pay：欠款
			agent_credit: function(nPage,store_id, type, callback,calldone) {
				Http.post({
					method: 'member.agenter.credit.getlist',
					store_id: store_id,
					pagelimit: 15,
					nPage: nPage,
					type:type
				}, function(result) {
					if(callback)
						callback(get_data_agent_credit(result).result);
				}, function(e) {

				}, function() {
					if(calldone)
					calldone();
				})
			},
			//确认还款/作废
			confrim_credit: function(member_id, info_id, money,cancel,callback) {
				Http.post({
					method: 'member.agenter.credit.confirm',
					member_id: member_id,
					info_id: info_id,
					money: money,
					cancel:cancel
				}, function(result) {
					if(callback)
						callback(result);
				}, function(e) {

				}, function() {

				})
			}

		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Creditrepayview", factory);
});